﻿using System.Linq;
using System.Web.Mvc;
using QDT.Common;
using QDT.Core.Projects;
using QDT.Web.Code;

namespace QDT.Web.Controllers
{
    public class AgencyController : BaseController
    {
        //
        // GET: /Agency/

        public ActionResult DSX(int? page)
        {
            const int pageSize = 6;
            var pageNumber = page ?? 1;

            var filter = PredicateExtensionses.True<Project>();
            var user = QDTContext.Current.User;

            if (user == null || user.GroupID != 1)
            {
                filter = filter.And(x => x.TypeID != 7);
            }

            var porject = DbProvider.D<Project>().Where(filter.And(x => !x.IsDelete && x.IsEffect && x.StartTime.HasValue && x.ID > 182 && !x.IsOffline && x.Parent.AgencyId == 5)).OrderByDescending(x => x.ID);
            return View(porject.ToPagedList(pageNumber - 1, pageSize));
        }

        public ActionResult ZYCT(int? page)
        {
            const int pageSize = 6;
            var pageNumber = page ?? 1;

            var filter = PredicateExtensionses.True<Project>();
            var user = QDTContext.Current.User;

            if (user == null || user.GroupID != 1)
            {
                filter = filter.And(x => x.TypeID != 7);
            }

            var porject = DbProvider.D<Project>().Where(filter.And(x => !x.IsDelete && x.IsEffect && x.StartTime.HasValue && x.ID > 182 && !x.IsOffline && x.Parent.AgencyId == 4)).OrderByDescending(x => x.ID);
            return View(porject.ToPagedList(pageNumber - 1, pageSize));
        }

        public ActionResult JDH(int? page)
        {
            const int pageSize = 6;
            var pageNumber = page ?? 1;

            var filter = PredicateExtensionses.True<Project>();
            var user = QDTContext.Current.User;

            if (user == null || user.GroupID != 1)
            {
                filter = filter.And(x => x.TypeID != 7);
            }

            var porject = DbProvider.D<Project>().Where(filter.And(x => !x.IsDelete && x.IsEffect && x.StartTime.HasValue && x.ID > 182 && !x.IsOffline && x.Parent.AgencyId == 2)).OrderByDescending(x => x.ID);
            return View(porject.ToPagedList(pageNumber - 1, pageSize));
        }

        public ActionResult FL(int? page)
        {
            const int pageSize = 6;
            var pageNumber = page ?? 1;

            var filter = PredicateExtensionses.True<Project>();
            var user = QDTContext.Current.User;

            if (user == null || user.GroupID != 1)
            {
                filter = filter.And(x => x.TypeID != 7);
            }

            var porject = DbProvider.D<Project>().Where(filter.And(x => !x.IsDelete && x.IsEffect && x.StartTime.HasValue && x.ID > 182 && !x.IsOffline && x.Parent.AgencyId == 1)).OrderByDescending(x => x.ID);
            return View(porject.ToPagedList(pageNumber - 1, pageSize));
        }

        public ActionResult GotoAction(int? agencyid)
        {
            if (agencyid != null)
            {
                switch (agencyid)
                {
                    case 5:
                        return RedirectToAction("DSX");
                        break;
                    case 4:
                        return RedirectToAction("ZYCT");
                         break;
                    case 2:
                        return RedirectToAction("JDH");
                        break;
                    case 1:
                        RedirectToAction("FL");
                        break;
                    default:
                        return RedirectToAction("DSX");
                }
            }

            return RedirectToAction("DSX");
        }

    }
}
